<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of tt_iterapp</title>
  <meta name="keywords" content="tt_iterapp">
  <meta name="description" content="Apply TT matrix operator to TT vector and error gracefully.">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">solve</a> &gt; tt_iterapp.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/solve&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>tt_iterapp
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>Apply TT matrix operator to TT vector and error gracefully.</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function y = tt_iterapp(op,afun,atype,afcnstr,x,eps,max_rank,max_swp,varargin) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">Apply TT matrix operator to TT vector and error gracefully.
   TT_ITERAPP(OP,AFUN,ATYPE,AFCNSTR,X) applies matrix operator AFUN to vector
   X. If ATYPE is 'matrix, then AFUN is a matrix and the OP is applied
   directly. OP is either 'mtimes' or 'mldivide'.
   ATYPE and AFCNSTR are used in case of error.
   ITERAPP(OP,AFUN,ATYPE,AFCNSTR,X,P1,P2,...) allows extra arguments to
   AFUN(X,P1,P2,...) although this usage is now discouraged in favor of
   using anonymous functions.
   AFUN(X,P1,P2,...,PN,TFLAG) should accept a TFLAG as its final input if
   the calling function is BICG, LSQR or QMR. TFLAG is either 'transp' or
   'notransp' depending on whether A' OP X or A OP X is required.
   ITERAPP is designed for use by iterative methods like PCG which
   require matrix operators AFUN representing matrices A to operate on
   vectors X and return A*X and may also have operators MFUN representing
   preconditioning matrices M operate on vectors X and return M\X.

   See also BICG, BICGSTAB, CGS, GMRES, LSQR, MINRES, PCG, QMR, SYMMLQ.</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/core/tt_compr2.html" class="code" title="function [tt] = tt_compr2(tt,eps, max_r)">tt_compr2</a>	Tensor rounding in TT1.0 format</li><li><a href="../../tt2/core/tt_mv.html" class="code" title="function [res]=tt_mv(mat,vec)">tt_mv</a>	Matrix-by-vector product in the TT1.0 format</li><li><a href="../../tt2/core/tt_mvk3.html" class="code" title="function [y,swp]=tt_mvk3(W, x, eps, varargin)">tt_mvk3</a>	Two-sided DMRG fast matrix-by-vector product, the best version</li><li><a href="../../tt2/exp/tt_smv.html" class="code" title="function [res]=tt_smv(sttm, vec)">tt_smv</a>	function [res]=tt_smv(sttm, vec)</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="tt_gmres.html" class="code" title="function [x,RESVEC,rw,rx] = tt_gmres(A, b, tol, maxout, maxin, eps_x, eps_z, M1, M2, M3, x0, verbose, varargin)">tt_gmres</a>	TT-GMRES method</li></ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function y = tt_iterapp(op,afun,atype,afcnstr,x,eps,max_rank,max_swp,varargin)</a>
0002 <span class="comment">%Apply TT matrix operator to TT vector and error gracefully.</span>
0003 <span class="comment">%   TT_ITERAPP(OP,AFUN,ATYPE,AFCNSTR,X) applies matrix operator AFUN to vector</span>
0004 <span class="comment">%   X. If ATYPE is 'matrix, then AFUN is a matrix and the OP is applied</span>
0005 <span class="comment">%   directly. OP is either 'mtimes' or 'mldivide'.</span>
0006 <span class="comment">%   ATYPE and AFCNSTR are used in case of error.</span>
0007 <span class="comment">%   ITERAPP(OP,AFUN,ATYPE,AFCNSTR,X,P1,P2,...) allows extra arguments to</span>
0008 <span class="comment">%   AFUN(X,P1,P2,...) although this usage is now discouraged in favor of</span>
0009 <span class="comment">%   using anonymous functions.</span>
0010 <span class="comment">%   AFUN(X,P1,P2,...,PN,TFLAG) should accept a TFLAG as its final input if</span>
0011 <span class="comment">%   the calling function is BICG, LSQR or QMR. TFLAG is either 'transp' or</span>
0012 <span class="comment">%   'notransp' depending on whether A' OP X or A OP X is required.</span>
0013 <span class="comment">%   ITERAPP is designed for use by iterative methods like PCG which</span>
0014 <span class="comment">%   require matrix operators AFUN representing matrices A to operate on</span>
0015 <span class="comment">%   vectors X and return A*X and may also have operators MFUN representing</span>
0016 <span class="comment">%   preconditioning matrices M operate on vectors X and return M\X.</span>
0017 <span class="comment">%</span>
0018 <span class="comment">%   See also BICG, BICGSTAB, CGS, GMRES, LSQR, MINRES, PCG, QMR, SYMMLQ.</span>
0019 
0020 <span class="comment">%   Copyright 1984-2008 The MathWorks, Inc.</span>
0021 <span class="comment">%   $Revision: 1.7.4.4 $ $Date: 2008/06/20 08:01:27 $</span>
0022 
0023 
0024 matvec_alg=<span class="string">'mv+compr'</span>;   <span class="comment">% produce matvec via tt_mv, and then tt_compr2</span>
0025 <span class="comment">% matvec_alg='mvk3';         % produce matvec via tt_mvk2</span>
0026 <span class="comment">% matvec_alg='smv+compr'; % produce matvec via SparseMatVec</span>
0027 <span class="comment">% matvec_alg='mv'; % Just a tt_mv (I guess we have to do a compression by ourselves)</span>
0028 
0029 <span class="keyword">if</span> strcmp(atype,<span class="string">'matrix'</span>)
0030     <span class="keyword">switch</span> lower(op)
0031         <span class="keyword">case</span> <span class="string">'mtimes'</span>
0032             <span class="keyword">if</span> (strcmp(matvec_alg,<span class="string">'mvk3'</span>))
0033                 y = <a href="../../tt2/core/tt_mvk3.html" class="code" title="function [y,swp]=tt_mvk3(W, x, eps, varargin)">tt_mvk3</a>(afun, x, eps, <span class="string">'rmax'</span>, max_rank, <span class="string">'nswp'</span>, max_swp, <span class="string">'verb'</span>, 0);                
0034             <span class="keyword">end</span>;
0035             <span class="keyword">if</span> (strcmp(matvec_alg,<span class="string">'mv+compr'</span>))
0036                 y = <a href="../../tt2/core/tt_mv.html" class="code" title="function [res]=tt_mv(mat,vec)">tt_mv</a>(afun, x);
0037                 y = <a href="../../tt2/core/tt_compr2.html" class="code" title="function [tt] = tt_compr2(tt,eps, max_r)">tt_compr2</a>(y, eps, max_rank);
0038             <span class="keyword">end</span>;
0039             <span class="keyword">if</span> (strcmp(matvec_alg,<span class="string">'smv+compr'</span>))
0040                 y = <a href="../../tt2/exp/tt_smv.html" class="code" title="function [res]=tt_smv(sttm, vec)">tt_smv</a>(afun, x);
0041                 y = <a href="../../tt2/core/tt_compr2.html" class="code" title="function [tt] = tt_compr2(tt,eps, max_r)">tt_compr2</a>(y, eps, max_rank);
0042             <span class="keyword">end</span>;
0043             <span class="keyword">if</span> (strcmp(matvec_alg,<span class="string">'mv'</span>))
0044                 y = <a href="../../tt2/core/tt_mv.html" class="code" title="function [res]=tt_mv(mat,vec)">tt_mv</a>(afun, x);
0045             <span class="keyword">end</span>;            
0046         <span class="keyword">case</span> <span class="string">'mldivide'</span>
0047             <span class="keyword">if</span> (strcmp(matvec_alg,<span class="string">'mvk3'</span>))
0048                 y = <a href="../../tt2/core/tt_mvk3.html" class="code" title="function [y,swp]=tt_mvk3(W, x, eps, varargin)">tt_mvk3</a>(afun, x, eps, <span class="string">'rmax'</span>, max_rank, <span class="string">'nswp'</span>, max_swp);                
0049             <span class="keyword">end</span>;
0050             <span class="keyword">if</span> (strcmp(matvec_alg,<span class="string">'mv+compr'</span>))
0051                 y = <a href="../../tt2/core/tt_mv.html" class="code" title="function [res]=tt_mv(mat,vec)">tt_mv</a>(afun, x);
0052                 y = <a href="../../tt2/core/tt_compr2.html" class="code" title="function [tt] = tt_compr2(tt,eps, max_r)">tt_compr2</a>(y, eps, max_rank);
0053             <span class="keyword">end</span>;
0054             <span class="keyword">if</span> (strcmp(matvec_alg,<span class="string">'smv+compr'</span>))
0055                 y = <a href="../../tt2/exp/tt_smv.html" class="code" title="function [res]=tt_smv(sttm, vec)">tt_smv</a>(afun, x);
0056                 y = <a href="../../tt2/core/tt_compr2.html" class="code" title="function [tt] = tt_compr2(tt,eps, max_r)">tt_compr2</a>(y, eps, max_rank);
0057             <span class="keyword">end</span>;
0058             <span class="keyword">if</span> (strcmp(matvec_alg,<span class="string">'mv'</span>))
0059                 y = <a href="../../tt2/core/tt_mv.html" class="code" title="function [res]=tt_mv(mat,vec)">tt_mv</a>(afun, x);
0060             <span class="keyword">end</span>;                        
0061         <span class="keyword">otherwise</span>
0062             error(<span class="string">'MATLAB:iterapp:InvalidOp'</span>, <span class="string">'Invalid operation.'</span>)
0063     <span class="keyword">end</span>
0064 <span class="keyword">else</span>
0065     <span class="keyword">try</span>
0066             y = afun(x,eps,max_rank,varargin{:});
0067     <span class="keyword">catch</span> ME
0068         error(<span class="string">'MATLAB:InvalidInput'</span>, [<span class="string">'user supplied %s ==&gt; %s\n'</span> <span class="keyword">...</span>
0069             <span class="string">'failed with the following error:\n\n%s'</span>], <span class="keyword">...</span>
0070             atype,afcnstr, ME.message);
0071     <span class="keyword">end</span>
0072 <span class="keyword">end</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>